import java.util.*;

class Solution {
    public int[] exchange(int[] nums) {
        if (nums == null || nums.length <= 1) return nums;
        int left = 0;
        int right = nums.length - 1;
        while (left < right - 1) {
            while (left < right && (nums[right] & 1) == 0) right--;
            while (left < right && (nums[left] & 1) == 1) left++;
            if (left != right) {
                nums[left] = nums[left] + nums[right];
                nums[right] = nums[left] - nums[right];
                nums[left] = nums[left] - nums[right];
            }
        }
        return nums;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution().exchange(new int[]{1, 3, 5})));
    }
}

